package com.tang.model.expresion.utils;

import com.tang.model.expresion.number.abst.IArithmeticInterpreter;
import com.tang.model.expresion.operator.impl.AddInterpreter;
import com.tang.model.expresion.operator.impl.DivInterpreter;
import com.tang.model.expresion.operator.impl.MultiInterpreter;
import com.tang.model.expresion.operator.impl.SubInterpreter;

import java.util.Objects;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/9/6 8:13
 * @Desc
 * @Remarks
 */
public class CalculatorUtil {
    public static boolean isOperator(String str) {
        return Objects.equals(str, "+") || Objects.equals(str, "-")
                || Objects.equals(str, "*") || Objects.equals(str, "/");
    }

    public static IArithmeticInterpreter createInterpreter(Integer left, Integer right, String element) {
        if (Objects.equals(element, "+")) {
            return new AddInterpreter(left, right);
        } else if (Objects.equals(element, "-")) {
            return new SubInterpreter(left, right);
        } else if (Objects.equals(element, "*")) {
            return new MultiInterpreter(left, right);
        } else if (Objects.equals(element, "/")) {
            return new DivInterpreter(left, right);
        }
        return null;

    }
}
